<?php
/**
 # com_jvframework - JV Framework
 # @version		1.5.x
 # ------------------------------------------------------------------------
 # author    Open Source Code Solutions Co
 # copyright Copyright (C) 2011 joomlavi.com. All Rights Reserved.
 # @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL or later.
 # Websites: http://www.joomlavi.com
 # Technical Support:  http://www.joomlavi.com/my-tickets.html
-------------------------------------------------------------------------*/

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

jimport( 'joomla.plugin.plugin' );

if(JFactory::getApplication()->isAdmin() == false && JFactory::getApplication()->getTemplate() == 'jv-framework'){
    JLoader::import('framework', JPATH_ADMINISTRATOR.DS.'components'.DS.'com_jvframework'.DS.'libraries'); JVFactory::getFramework(JFactory::getDocument(), 'site');
    JLoader::import('view', JPATH_ADMINISTRATOR.DS.'components'.DS.'com_jvframework'.DS.'libraries'.DS.'joomla'); 
    JLoader::import('modulehelper',JPATH_ADMINISTRATOR.DS.'components'.DS.'com_jvframework'.DS.'libraries'.DS.'joomla');    
    JLoader::import('pagination', JPATH_ADMINISTRATOR.DS.'components'.DS.'com_jvframework'.DS.'libraries'.DS.'joomla'); 
}  

class plgSystemJVFramework extends JPlugin{
    
    function onAfterInitialise(){ 
        $config = JFactory::getConfig();
        if($config->getValue('editor') == 'jce'){
            jimport('joomla.application.component.model');
                
            if(is_file(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_jce'.DS.'includes'.DS.'loader.php')){                    
                JLoader::import('loader', JPATH_ADMINISTRATOR.DS.'components'.DS.'com_jce'.DS.'includes');
                JLoader::import('editor', JPATH_ADMINISTRATOR.DS.'components'.DS.'com_jvframework'.DS.'libraries'.DS.'joomla');                    
            }
            
        }     
        
    }
    
    function onGetStyleSheets(&$path, &$url){
        $WFModelEditor = JModel::getInstance('Editor', 'WFModel');
                
        if($WFModelEditor->getSiteTemplate() == 'jv-framework'){
            $theme= $this->getDefautTheme();
            $path = JPATH_SITE.DS.'templates'.DS.'jv-framework'.DS.'themes'.DS.$theme.DS.'css';
            $url  = "templates/jv-framework/themes/$theme/css";
        }
    }
    
    function getDefautTheme() {
        $theme = '';
        $data =& JFactory::getDBO();
        $data->setQuery('SELECT id, theme FROM #__jv_themes WHERE home=1');
        $theme = $data->loadObject();
        if(is_object($theme)){
            $theme = current(explode('|', $theme->theme));
        }
        
        return $theme;        
    }    
}
